package com.wc.alorithm_blue_bridge._DFS.路径之谜;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/3/10 15:44
 * @description
 * https://www.lanqiao.cn/courses/46292/learning/?id=3441387&compatibility=false
 */
public class Main {
    /**
     * 思路：dfs
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 25;
    static boolean[][] st = new boolean[N][N];
    static int[] col = new int[N], row = new int[N];
    static int[] dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
    static int[] q = new int[N * N];
    static int n, k;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 0; i < n; i++) col[i] = sc.nextInt();
        for (int i = 0; i < n; i++) row[i] = sc.nextInt();
        dfs(0, 0, 0);
        for (int i = 0; i < k; i++) out.print(q[i] + " ");
        out.println();
        out.flush();
    }

    static void dfs(int u, int x, int y) {
        if (k > 0) return;
        q[u] = x * n + y;
        st[x][y] = true;
        row[x]--;
        col[y]--;

        if (x == n - 1 && y == n - 1) {
            for (int i = 0; i < n; i++) {
                if (col[i] != 0 || row[i] != 0) return;
            }
            k = u + 1;
            return;
        }

        for (int i = 0; i < 4; i++) {
            int a = x + dx[i], b = y + dy[i];
            if (a >= n || a < 0 || b >= n || b < 0) continue;
            if (st[a][b]) continue;
            if (row[a] <= 0 || col[b] <= 0) continue;

            dfs(u + 1, a, b);
            st[a][b] = false;
            row[a]++;
            col[b]++;
        }
    }

}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

